package com.ws.q1.controller;

import com.ws.q1.bean.GongYingShang;
import com.ws.q1.bean.YouQingLianJie;
import com.ws.q1.service.YouQingLianJieService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.sql.SQLException;
import java.util.List;

@Controller
@RequestMapping("/you")
public class YouQingLianJieController {
    @Autowired
    private YouQingLianJieService youQingLianJieService;

    @RequestMapping("add")
    public String add(YouQingLianJie youQingLianJie) {
        int add = youQingLianJieService.add(youQingLianJie);
        if (add > 0) {
            return "redirect:/you/list";
        } else {
            return "redirect:/you/list";
        }
    }

    @RequestMapping("list")
    public String list(Model model) throws SQLException {
        List<YouQingLianJie> list = youQingLianJieService.list();
        model.addAttribute("list", list);
        return "youqinglianjie/list";
    }

    @RequestMapping("delete")
    public String delete(Integer id) {
        youQingLianJieService.deleteById(id);
        return "redirect:/you/list";
    }


    @RequestMapping("huixian")
    public String huixian(Integer id, Model model) {
        System.out.println(id);
        YouQingLianJie huixian = youQingLianJieService.huixian(id);
        System.out.println(huixian);
        model.addAttribute("huixian", huixian);
        return "youqinglianjie/update";
    }

    @RequestMapping("update")
    public String update(YouQingLianJie youQingLianJie) {
        int id = youQingLianJie.getId();
        youQingLianJieService.update(id,youQingLianJie);
        return "redirect:/you/list";
    }


    @RequestMapping("tiao")
    public String tiao() {
        return "youqinglianjie/add";
    }

}
